﻿using System;
using System.ComponentModel;
using System.Data;

namespace DCSoft.TemperatureChart
{
    internal class MeasureBindingList : BindingList<Measure>
    {
        private MeasureList _ParentList = null;

        public MeasureList ParentList
        {
            get { return _ParentList; }
            set { _ParentList = value; }
        }
        protected override void RemoveItem(int index)
        {
            base.RemoveItem(index);
        }
        private bool _DataModified = false;

        public bool DataModified
        {
            get { return _DataModified; }
            set { _DataModified = value; }
        }

        private DateTime _CurrentDate = DateTime.Now;

        public DateTime CurrentDate
        {
            get { return _CurrentDate; }
            set { _CurrentDate = value; }
        }

        protected override void OnListChanged(ListChangedEventArgs e)
        {
            base.OnListChanged(e);
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
                Measure record = this[e.NewIndex];
                record.RecordState = DataRowState.Added;
                record.ValueDate = this.CurrentDate;
                record.SetDefaultValue();
            }
            else if (e.ListChangedType == ListChangedType.ItemChanged)
            {
                this[e.NewIndex].RecordState = DataRowState.Modified;
            }
            this.DataModified = true;
        }
    }
}
